//
//  Ext+NSAttributedString.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/2/13.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit

extension NSAttributedString{
    
    class func emotionAttributedString(emotionModel:QCEmotionModel) -> NSAttributedString{
        //创建一个文本附件
        let att = QCTextAttachment()
        
        //赋值
        att.emotionModel = emotionModel
        
        let path = emotionModel.path ?? ""
        
        //获取bundle文件中图片
        
        let image = UIImage(named: path, in: QCEmotionTools.shared.emotionBundle, compatibleWith: nil)
        
        //设置image
        att.image = image
        
        //得到行号
        let font = UIFont.systemFont(ofSize: QCNORMALFONTSIZE)
        
        let lineHeight = font.lineHeight
        
        //bounds
        att.bounds = CGRect(x: 0, y: -4, width: lineHeight, height: lineHeight)
        //定义一个不可变的富文本
        let attr = NSAttributedString(attachment: att)
        
        return attr
        
    }
    
    
}
